package memory;

import java.util.ArrayList;
import java.util.List;

import process.Process;

public class PCBData {
	public static List<Block> Blist = new ArrayList<Block>() {
		{
			add(new Block(512, false, 0, 0));
		}
	};
	public static List<PCB> readyList = new ArrayList<PCB>();
	public static List<PCB> allPcbList = new ArrayList<PCB>();
	public static List<PCB> blockQueue = new ArrayList<PCB>();
	public static String str = ""; // +

	public static int blockPCBIndex(int pid) {
		for (int i = 0; i < PCBData.blockQueue.size(); i++) {
			if (PCBData.blockQueue.get(i).getPid() == pid) {
				System.out.println(PCBData.blockQueue.get(i).getPid()+"  "+pid);
				return i;
			}
		}
		return -1;
	}

	// 寻找等待获得某个设备的阻塞进程
	public static int searchWait(char type) {
		if (PCBData.blockQueue.size() > 0) {
			for (int i = 0; i < PCBData.blockQueue.size(); i++) {
				if (PCBData.blockQueue.get(i).getType()==type) {
					return i;
				}
			}
			return -1;
		}
		else
			return -1;
	}

	// 闲逛进程
	private static PCB hangOutPcb;

	public static PCB getHangOutPcb() {
		if (hangOutPcb == null) {
			hangOutPcb = new PCB();
			hangOutPcb.setProcess(Process.getHangOutProcess());
			
			hangOutPcb.setPid(-1);
			hangOutPcb.setAx(0);
			hangOutPcb.setPc(0);
			hangOutPcb.setPsw_io(0);
			hangOutPcb.setPsw_process_end(0);
			// 考虑是否需要设置其他值
		}
		return hangOutPcb;
	}
}
